<template>
  <div class="box">
    <div class="header">
      <div><input type="text" /><button>搜索</button></div>
      <div>
        <button @click="isshow = true">添加</button>
      </div>
    </div>

    <div class="body">
      <table border="1">
        <thead>
          <tr>
            <th>序号</th>
            <th>标题</th>
            <th>内容</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in mydata" :key="index">
            <td>{{ index + 1 }}</td>
            <td>{{ item.title }}</td>
            <td>{{ item.text }}</td>
            <td>
              <button @click="updata(index)">修改</button
              ><button @click="isshow3 = true">删除</button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <v-popup
      v-if="isshow"
      @setshow="setshow"
      :biaoti="'添加'"
      :myisshow="isshow"
      :mydata="mydata"
    ></v-popup>
    <v-popup
      v-if="isshow"
      @setshow="setshow"
      :biaoti="'修改'"
      :myisshow="isshow"
      :mydata="mydata"
    ></v-popup>
    <v-popup
      v-if="isshow"
      @setshow="setshow"
      :biaoti="'删除'"
      :myisshow="isshow"
      :mydata="mydata"
    ></v-popup>
  </div>
</template>

<script>
import vPopup from "./popup.vue";
export default {
  data() {
    return {
      isshow: false,
      isshow2: false,
      isshow3: false,
      index: 0,
      mydata: [
        {
          title: "娱乐新闻",
          text: "娱乐新闻内容",
        },
      ],
    };
  },
  components: {
    vPopup,
  },
  methods: {
    setshow(e) {
      this.isshow = false;
      this.isshow2 = false;
      this.isshow3 = false;
    console.log(e);
      if (e) {
        this.mydata.unshift({ ...e });
      }
      
    },
    updata(index) {
      this.isshow2 = true;

      this.index = index;
      // console.log(this.mydata[this.index]);
    },
  },
};
</script>

<style scoped>
.box {
  width: 100%;
  height: 100vh;
  background-color: #ededed;
  padding: 20px 30px;
}
.header {
  width: 100%;
  margin: 10px 0px;
  /* height: 50px; */
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
}
.body {
  width: 100%;
  height: 90%;
  border: 1px solid #5452bf;
}
table {
  border-collapse: collapse;
  width: 800px;
  margin: 0px auto;
}
td {
  text-align: center;
  height: 30px;
  line-height: 30px;
}
</style>>


